<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/8/22
 * Time: 18:06
 */
class 加密和解密
{

}
function selfEncode($str, $k) {
    $encoded = '';
    $len = strlen($str);
    $lk = strlen($k);
    for($i = 0; $i < $len; $i++)
    {
        $mod = fmod($i, $lk);
        $encoded .= $str[$i. ''] ^ $k[$mod.''];
    }
    $encoded = base64_encode($encoded);

    return $encoded;
}
function selfDecode($str, $k) {
    $str = base64_decode($str);
    $decoded = '';
    $len = strlen($str);
    $lk = strlen($k);
    for($i = 0; $i < $len; $i++)
    {
        $mod = fmod($i, $lk);
        $decoded .= $str[$i. ''] ^ $k[$mod.''];
    }

    return $decoded;
}

// 注意： $str 和 $k 都是字符串类型